package com.library.controller;

import com.library.entity.CourseSchedule;
import com.library.entity.StudentInfo;
import com.library.service.CourseScheduleService;
import com.library.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class CourseScheduleController {

    public static final String prefix = "/api/courseSchedule";

    @Autowired
    public CourseScheduleService studentInfoService;

    @RequestMapping("courseSchedule.html")
    public ModelAndView allBooks() {
        ArrayList<StudentInfo> readers = new ArrayList<>();
        ModelAndView modelAndView = new ModelAndView("courseSchedule");
        return modelAndView;
    }

    @RequestMapping(path = prefix + "/list",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult list(@RequestBody CourseReq studentInfo) {
        P<List<CourseSchedule>> list1 = this.studentInfoService.list(studentInfo);
        return BaseResult.successWithData(list1);
    }

    @RequestMapping(path = prefix + "/add",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult add(@RequestBody CourseSchedule studentInfo) {
        this.studentInfoService.add(studentInfo);
        return BaseResult.success();
    }

    @RequestMapping(path = prefix + "/delete",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult delete(@RequestBody CourseSchedule studentInfo) {
        this.studentInfoService.delete(studentInfo);
        return BaseResult.success();
    }

    @RequestMapping(path = prefix + "/update",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult update(@RequestBody CourseSchedule studentInfo) {
        this.studentInfoService.update(studentInfo);
        return BaseResult.success();
    }

    @RequestMapping(path = prefix + "/detail",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult detail(@RequestBody CourseSchedule studentInfo) {
        CourseSchedule detail = this.studentInfoService.detail(studentInfo);
        return BaseResult.successWithData(detail);
    }
}
